<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopWithdrawTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_withdraw', ['comment' => '用户提现', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '提现用户'])
            ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '提现金额'])
            ->addColumn('paid_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '实际到账'])
            ->addColumn('charge_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '手续费'])
            ->addColumn('charge_rate', 'decimal', ['precision' => 10, 'scale' => 3, 'default' => 0, 'comment' => '手续费率'])
            ->addColumn('withdraw_sn', 'string', ['limit' => 191, 'comment' => '提现单号'])
            ->addColumn(Column::enum('withdraw_type', ['bank', 'wechat', 'alipay'])->setComment('提现类型:bank=银行卡,wechat=微信零钱,alipay=支付宝账户'))
            ->addColumn('withdraw_info', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '提现信息'])
            ->addColumn(Column::tinyInteger('status')->setDefault(0)->setComment('提现状态:-1=已拒绝,0=待审核,1=处理中,2=已处理'))
            ->addColumn(Column::enum('platform', ['H5', 'App', 'WechatOfficialAccount', 'WechatMiniProgram'])->setNull(true)->setDefault(null)->setComment('平台:H5=H5,WechatOfficialAccount=微信公众号,WechatMiniProgram=微信小程序,App=App'))
            ->addColumn('payment_json', 'string', ['limit' => 2500, 'null' => true, 'default' => null, 'comment' => '交易原始数据'])
            // ->addColumn('logs', 'text', ['null' => true, 'comment' => '操作日志'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('withdraw_sn', ['unique' => true])
            ->create();


        $table = $this->table('shop_withdraw_log', ['comment' => '提现日志', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('withdraw_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '提现ID'])
            ->addColumn('content', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '日志内容'])
            ->addColumn('oper_type', 'string', ['limit' => 50, 'null' => true, 'default' => null, 'comment' => '操作人类型'])
            ->addColumn('oper_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '操作人'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->create();
    }


    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_withdraw');
        $table->drop();
    }
}
